'''###########################################################################################################################
### File: rayman-panda3d.py
### Name: Patrick Delaney, Andrew Oberlin
### Class: CSE 487
### Instructor: Dr.Zmuda
### Assignment: Final Project
### Description: Pending
################ 
'''
from menu_button import MenuButton
from panda3d.core import Vec2, Point3, Vec3, Vec4
from pandac.PandaModules import TextNode

class LevelObjectEditingGUI:
	'''
		Level Object Constructor
	'''
	def __init__(self, parent, object):
		self.parent = parent
		self.object = object
		self.minimized = False
		self.models = dict()
		self.labels = dict()
		self.__loadModels()
		
	'''
	
	'''
	def __loadModels(self):
	
		self.models['dummy'] = self.parent.base.aspect2d.attachNewNode('dummy_level_object_editing_gui')
		self.models['dummy'].setZ(-0.85)
	
		self.models['background'] = self.parent.loader.loadModelCopy("models/plane")
		self.backgroundTexture = self.parent.loader.loadTexture("models/gui/game_maker/menu_background.jpg")
		self.models['background'].setTexture(self.backgroundTexture)
		self.models['background'].setTransparency(1)
		self.models['background'].setScale(2.67, 1, 0.5)
		self.models['background'].reparentTo(self.models['dummy'])
		
		#### Vertical scaling buttons
		self.labels['vertical_scaling_label_text'] = TextNode('vertical_scaling_label_text')
		self.labels['vertical_scaling_label_text'].setText("Vertical Scaling")
		self.models['vertical_scaling_label'] = self.models['dummy'].attachNewNode(self.labels['vertical_scaling_label_text'])
		self.models['vertical_scaling_label'].setScale(Vec3(0.10,0.10,0.075))
		self.models['vertical_scaling_label'].setPos(-1.25, 0, 0.165)
		
		self.models['scale_vertical_plus'] = MenuButton(
			self.parent, 'scale_verticalP_plus_button', 'models/gui/game_maker/dialog_button', 
			self.verticalScalePlus, Vec3(-0.15, 0, 0.175), isMovie = False, text="+", 
			textPos=Vec3(-0.0275, 0, -0.015), scale=Vec3(0.1,1,0.1)
		)
		self.models['scale_vertical_plus'].reparentTo(self.models['dummy'])
		
		self.models['scale_vertical_minus'] = MenuButton(
			self.parent, 'scale_verticalP_minus_button', 'models/gui/game_maker/dialog_button', 
			self.verticalScaleMinus, Vec3(-0.35, 0, 0.175), isMovie = False, text="-", 
			textPos=Vec3(-0.025, 0, -0.015), scale=Vec3(0.1,1,0.1)
		)
		self.models['scale_vertical_minus'].reparentTo(self.models['dummy'])
		
		### Horizontl scaling buttons
		self.labels['horizontal_scaling_label_text'] = TextNode('horizontal_scaling_label_text')
		self.labels['horizontal_scaling_label_text'].setText("Horizontal Scaling")
		self.models['horizontal_scaling_label'] = self.models['dummy'].attachNewNode(self.labels['horizontal_scaling_label_text'])
		self.models['horizontal_scaling_label'].setScale(Vec3(0.10,0.10,0.075))
		self.models['horizontal_scaling_label'].setPos(-1.25, 0, -0.01)
		
		self.models['scale_horizontal_plus'] = MenuButton(
			self.parent, 'scale_horizontal_plus_button', 'models/gui/game_maker/dialog_button', 
			self.horizontalScalePlus, Vec3(-0.15, 0, 0), isMovie = False, text="+", 
			textPos=Vec3(-0.0275, 0, -0.015), scale=Vec3(0.1,1,0.1)
		)
		self.models['scale_horizontal_plus'].reparentTo(self.models['dummy'])
		
		self.models['scale_horizontal_minus'] = MenuButton(
			self.parent, 'scale_horizontal_minus_button', 'models/gui/game_maker/dialog_button', 
			self.horizontalScaleMinus, Vec3(-0.35, 0, 0), isMovie = False, text="-", 
			textPos=Vec3(-0.025, 0, -0.015), scale=Vec3(0.1,1,0.1)
		)
		self.models['scale_horizontal_minus'].reparentTo(self.models['dummy'])
		
		### minimize and maximize button
		self.models['min_max_button'] = MenuButton(
			self.parent, 'min_max_button', 'models/gui/game_maker/dialog_button', 
			self.minimizeMaximize, Vec3(1.3, 0, 0.20), isMovie = False, text="x", 
			textPos=Vec3(-0.025, 0, -0.015), scale=Vec3(0.1, 1,0.1)
		)
				
		self.models['min_max_button'].reparentTo(self.models['dummy'])

		### collision type buttons and label
		self.labels['collision_type_label_text'] = TextNode('collision_type_label_text')
		self.labels['collision_type_label_text'].setText("CollisionType")
		self.models['collision_type_label'] = self.models['dummy'].attachNewNode(self.labels['collision_type_label_text'])
		self.models['collision_type_label'].setScale(Vec3(0.10,0.10,0.075))
		self.models['collision_type_label'].setPos(-0.10, 0, -0.125)
		
		self.models['collision_type_cylinder'] = MenuButton(
			self.parent, 'collision_type_cylinder', 'models/gui/game_maker/dialog_button', 
			self.setCollisionTypeCyl, Vec3(0.75, 0, -0.1), isMovie = False, text="Cylinder", 
			textPos=Vec3(-0.195, 0, -0.015), scale=Vec3(0.4,1,0.1)
		)
		self.models['collision_type_cylinder'].reparentTo(self.models['dummy'])
		
		self.models['collision_type_sphere'] = MenuButton(
			self.parent, 'collision_type_sphere', 'models/gui/game_maker/dialog_button', 
			self.setCollisionTypeSphere, Vec3(1.20, 0, -0.1), isMovie = False, text="Sphere", 
			textPos=Vec3(-0.195, 0, -0.015), scale=Vec3(0.4,1,0.1)
		)
		self.models['collision_type_sphere'].reparentTo(self.models['dummy'])
		
		
		#### Vertical collision scaling buttons
		self.labels['vertical_scaling_collision_label_text'] = TextNode('vertical_scaling_label_text')
		self.labels['vertical_scaling_collision_label_text'].setText("Collision V Scale")
		self.models['vertical_scaling_collision_label'] = self.models['dummy'].attachNewNode(self.labels['vertical_scaling_collision_label_text'])
		self.models['vertical_scaling_collision_label'].setScale(Vec3(0.10,0.10,0.075))
		self.models['vertical_scaling_collision_label'].setPos(-0.05, 0, 0.165)
		
		self.models['scale_vertical_collision_plus'] = MenuButton(
			self.parent, 'scale_vertical_collision_plus_button', 'models/gui/game_maker/dialog_button', 
			self.increaseCollisionVertical, Vec3(1.05, 0, 0.175), isMovie = False, text="+", 
			textPos=Vec3(-0.0275, 0, -0.015), scale=Vec3(0.1,1,0.1)
		)
		self.models['scale_vertical_collision_plus'].reparentTo(self.models['dummy'])
		
		self.models['scale_vertical_collision_minus'] = MenuButton(
			self.parent, 'scale_vertical_collision_minus_button', 'models/gui/game_maker/dialog_button', 
			self.decreaseCollisionVertical, Vec3(0.85, 0, 0.175), isMovie = False, text="-", 
			textPos=Vec3(-0.025, 0, -0.015), scale=Vec3(0.1,1,0.1)
		)
		self.models['scale_vertical_collision_minus'].reparentTo(self.models['dummy'])
		
		### Horizontal collision scaling buttons
		self.labels['horizontal_scaling_collision_label_text'] = TextNode('horizontal_scaling_collision_label_text')
		self.labels['horizontal_scaling_collision_label_text'].setText("Collision H Scale")
		self.models['horizontal_scaling_collision_label'] = self.models['dummy'].attachNewNode(self.labels['horizontal_scaling_collision_label_text'])
		self.models['horizontal_scaling_collision_label'].setScale(Vec3(0.10,0.10,0.075))
		self.models['horizontal_scaling_collision_label'].setPos(-0.05, 0, -0.01)
		
		self.models['scale_horizontal_collision_plus'] = MenuButton(
			self.parent, 'scale_horizontal_collision_plus_button', 'models/gui/game_maker/dialog_button', 
			self.increaseCollisionHorizontal, Vec3(1.05, 0, 0), isMovie = False, text="+", 
			textPos=Vec3(-0.0275, 0, -0.015), scale=Vec3(0.1,1,0.1)
		)
		self.models['scale_horizontal_collision_plus'].reparentTo(self.models['dummy'])
		
		self.models['scale_horizontal_collision_minus'] = MenuButton(
			self.parent, 'scale_horizontal_collision_minus_button', 'models/gui/game_maker/dialog_button', 
			self.decreaseCollisionHorizontal, Vec3(0.85, 0, 0), isMovie = False, text="-", 
			textPos=Vec3(-0.025, 0, -0.015), scale=Vec3(0.1,1,0.1)
		)
		self.models['scale_horizontal_collision_minus'].reparentTo(self.models['dummy'])
		
		
	def verticalScale(self):
		print "scaling!"
		
	def minimizeMaximize(self):
		if (self.minimized):
			self.models['dummy'].setZ(-0.85)
			self.minimized = False
		else:
			self.models['dummy'].setZ(-1.15)
			self.minimized = True
			
	def destroy(self):
		self.models['dummy'].removeNode()
		
	def verticalScalePlus(self):
		scale = self.object.getScale()
		self.object.setScale(scale + Vec3(0, 0, 0.1))
		
	def verticalScaleMinus(self):
		scale = self.object.getScale()
		self.object.setScale(scale + Vec3(0, 0, -0.1))
		
	def horizontalScalePlus(self):
		scale = self.object.getScale()
		self.object.setScale(scale + Vec3(0.1, 0, 0))
		
	def horizontalScaleMinus(self):
		scale = self.object.getScale()
		self.object.setScale(scale + Vec3(-0.1, 0, 0))
		
	def setCollisionTypeCyl(self):
		self.object.addCollisionCyl()
		
	def setCollisionTypeSphere(self):
		self.object.addCollisionSphere()
		
	def increaseCollisionHorizontal(self):	
		self.object.increaseCollisionScale('x')
		
	def decreaseCollisionHorizontal(self):	
		self.object.decreaseCollisionScale('x')
		
	def increaseCollisionVertical(self):
		self.object.increaseCollisionScale('z')
	
	def decreaseCollisionVertical(self):
		self.object.decreaseCollisionScale('z')